#include<bits/stdc++.h>
using namespace std;
int main(){
    string str = "";
    int flag = 0;
    cin >> str;
    long long sum = 0;
    for(int i = str.size()-1; i >= 0; i--){
        long long temp = str[i] >= '0'&&str[i] <= '9' ? str[i] - '0':str[i] - 'A' +10;
        for(int j = 0; j < flag; j++){
            temp *= 16; 
        }
        sum += temp;
        flag++;
    }
    cout << sum;
    return 0;
}